using System.Diagnostics;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[RequireComponent(typeof(FPSRayActive))]
public class CharacterSystem : DamageManager
{
	[SyncVar]
	[HideInInspector]
	public string CharacterKey = string.Empty;

	[HideInInspector]
	public CharacterInventory inventory;

	[HideInInspector]
	public Animator animator;

	[HideInInspector]
	public FPSRayActive rayActive;

	[HideInInspector]
	public CharacterController controller;

	[HideInInspector]
	public CharacterMotor Motor;

	[HideInInspector]
	public bool Sprint;

	[HideInInspector]
	public bool IsMine;

	[Header("Moving")]
	public BodyStatePreset[] MovementPreset = new BodyStatePreset[1]
	{
		new BodyStatePreset()
	};

	[HideInInspector]
	public float CurrentMoveSpeed = 0.9f;

	[HideInInspector]
	public float CurrentMoveSpeedMax = 1.5f;

	public float TurnSpeed = 5f;

	[SyncVar]
	public byte MovementIndex;

	[HideInInspector]
	public Vector3 MoveVelocity;

	[Header("Attack")]
	public float PrimaryWeaponDistance = 1f;

	public int PrimaryItemType;

	public int AttackType;

	public byte Damage = 2;

	public float DamageLength = 1f;

	public byte Penetrate = 1;

	public Vector3 DamageOffset = Vector3.up;

	[Header("Sound")]
	public AudioClip[] DamageSound;

	public AudioClip[] SoundIdle;

	[Header("Networking")]
	public float SendRate = 5f;

	public float FarSendRate = 0.5f;

	public float SyncDistance = 10f;

	[HideInInspector]
	public bool isSeeAround;

	[HideInInspector]
	public float currentSendingRate;

	[HideInInspector]
	public bool isServerControl;

	[HideInInspector]
	public float spdMovAtkMult = 1f;

	[SyncVar]
	private Vector3 positionSync;

	[SyncVar]
	private float rotationYSync;

	private Vector3 positionSyncTmp;

	private float rotationYSyncTmp;

	private Vector3 positionLastTrip;

	private Vector3 positionLate;

	private float timeTmpsending;

	private float timeLastTrip;

	private float latencyTime;

	private Vector3 positionInterpolate;

	private Quaternion rotationInterpolate;

	private Vector3 previousPosition;

	private float updateTimeTmp;

	private bool jumped;

	private float sidevel;

	private static int kCmdCmdChangeState;

	private static int kRpcRpcChangeState;

	private static int kCmdCmdUpdateTransform;

	private static int kRpcRpcAttackAnimation;

	private static int kCmdCmdAttackAnimation;

	private static int kCmdCmdattackTo;

	private static int kCmdCmddoDamage;

	private static int kRpcRpcdoDamage;

	private static int kCmdCmddoDamagebyItemIndex;

	private static int kRpcRpcdoDamagebyItemIndex;

	private static int kCmdCmddoOverlapDamage;

	private static int kRpcRpcdoOverlapDamage;

	private static int kTargetRpcTargetReciveItem;

	private static int kTargetRpcTargetReciveItemBackpack;

	private static int kTargetRpcTargetReciveStock;

	private static int kCmdCmdDirectObjectInteractive;

	private static int kCmdCmdInteractive;

	private static int kCmdCmdSaveCharacterData;

	private static int kCmdCmdGetSaveData;

	private static int kTargetRpcTargetGetData;

	private static int kCmdCmdRequestSpawnObject;

	private static int kCmdCmdRequestThrowObject;

	private static int kCmdCmdSendMessage;

	private static int kRpcRpcGotMessage;

	private static int kCmdCmdOnSpawned;

	private static int kRpcRpcOnSpawned;

	public string NetworkCharacterKey
	{
		get
		{
			return CharacterKey;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref CharacterKey, 64u);
		}
	}

	public byte NetworkMovementIndex
	{
		get
		{
			return MovementIndex;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref MovementIndex, 128u);
		}
	}

	public Vector3 NetworkpositionSync
	{
		get
		{
			return positionSync;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref positionSync, 256u);
		}
	}

	public float NetworkrotationYSync
	{
		get
		{
			return rotationYSync;
		}
		[param: In]
		set
		{
			SetSyncVar(value, ref rotationYSync, 512u);
		}
	}

	public override void Awake()
	{
		SetupAwake();
		base.Awake();
	}

	public void SetupAwake()
	{
		Motor = GetComponent<CharacterMotor>();
		controller = GetComponent<CharacterController>();
		Audiosource = GetComponent<AudioSource>();
		animator = GetComponent<Animator>();
		rayActive = GetComponent<FPSRayActive>();
		inventory = GetComponent<CharacterInventory>();
		spdMovAtkMult = 1f;
		NetworkpositionSync = base.transform.position;
		Vector3 eulerAngles = base.transform.rotation.eulerAngles;
		NetworkrotationYSync = eulerAngles.y;
		positionLate = positionSync;
		positionLastTrip = positionSync;
		animator.SetFloat("Velocity", 0.25f);
		animator.SetFloat("SideVelocity", 0.25f);
		if ((bool)animator)
		{
			animator.applyRootMotion = false;
		}
	}

	public override void Update()
	{
		UpdateFunction();
		base.Update();
	}

	public void UpdateFunction()
	{
		currentSendingRate = SendRate;
		if ((bool)UnitZ.gameManager && UnitZ.gameManager.UserID == UserID && NetID != -1)
		{
			IsMine = true;
		}
		else
		{
			IsMine = false;
		}
		if (Time.time > updateTimeTmp + 1f)
		{
			isSeeAround = UnitZ.aiManager.IsPlayerAround(base.gameObject, SyncDistance);
			updateTimeTmp = Time.time;
		}
		if (!isSeeAround)
		{
			currentSendingRate = FarSendRate;
		}
		UpdatePosition();
	}

	public virtual void PlayAttackAnimation(bool attacking, int attacktype)
	{
	}

	public virtual void PlayMoveAnimation(float magnitude, float side)
	{
	}

	public virtual void Jump()
	{
		if (Motor.IsGroundedTest() && !jumped)
		{
			animator.SetTrigger("Jump");
			jumped = true;
		}
		else
		{
			jumped = false;
		}
	}

	public virtual void Reload()
	{
		if (inventory != null && inventory.FPSEquipment != null && inventory.FPSEquipment.Reload())
		{
			animator.SetTrigger("Reload");
		}
	}

	public void Sit()
	{
		if (Motor.grounded)
		{
			CallCmdChangeState((byte)(MovementIndex + 1));
		}
	}

	public void Sit(byte state)
	{
		CallCmdChangeState(state);
	}

	[Command(channel = 0)]
	private void CmdChangeState(byte state)
	{
		CallRpcChangeState(state);
	}

	[ClientRpc(channel = 0)]
	private void RpcChangeState(byte state)
	{
		NetworkMovementIndex = state;
		if (MovementIndex >= MovementPreset.Length)
		{
			NetworkMovementIndex = 0;
		}
	}

	public void MoveAnimation()
	{
		if (base.transform.parent == null)
		{
			if ((Motor != null && Motor.grounded) || Motor == null)
			{
				float num = Vector3.Dot(MoveVelocity, base.transform.forward);
				float b = Vector3.Dot(MoveVelocity, base.transform.right);
                if (num < 1f && num > -1f&&num!=0)
				{
					num = 1f;
				}
				if (num < 1f && num < 0f)
				{
					num = -1f;
				}
				float magnitude = MoveVelocity.magnitude * num;
				sidevel = Mathf.Lerp(sidevel, b, 20f * Time.deltaTime);
                PlayMoveAnimation(magnitude, sidevel);
			}
		}
		else
		{
			MoveVelocity = Vector3.zero;
			PlayMoveAnimation(0f, 0f);
        }
	}

	public float GetCurrentMoveSpeed()
	{
		float num = CurrentMoveSpeed;
		float num2 = CurrentMoveSpeedMax;
		if (MovementIndex >= MovementPreset.Length)
		{
			NetworkMovementIndex = 0;
		}
		if (MovementPreset.Length > MovementIndex)
		{
			num = MovementPreset[MovementIndex].MoveSpeed;
			num2 = MovementPreset[MovementIndex].MoveSpeedMax;
		}
		if (Sprint)
		{
			num = num2;
		}
		CurrentMoveSpeedMax = num2;
		CurrentMoveSpeed = num;
		return num;
	}

	public void MoveTo(Vector3 dir)
	{
		float currentMoveSpeed = GetCurrentMoveSpeed();
		Move(dir * currentMoveSpeed * spdMovAtkMult);
	}

	public void MoveToPosition(Vector3 position)
	{
		float currentMoveSpeed = GetCurrentMoveSpeed();
		Vector3 vector = position - base.transform.position;
		vector = Vector3.ClampMagnitude(vector, 1f);
		vector.y = 0f;
		Move(vector.normalized * currentMoveSpeed * vector.magnitude * spdMovAtkMult);
		if (vector != Vector3.zero)
		{
			Quaternion b = Quaternion.LookRotation(vector);
			base.transform.rotation = Quaternion.Slerp(base.transform.rotation, b, Time.deltaTime * vector.magnitude);
		}
	}

	public void OnTransformSyn()
	{
		if (rotationYSyncTmp != rotationYSync || positionSyncTmp != positionSync)
		{
			positionLate = positionLastTrip;
			latencyTime = Time.time - timeLastTrip;
			timeLastTrip = Time.time;
			positionLastTrip = positionSync;
			positionInterpolate = base.transform.position;
			rotationInterpolate = base.transform.rotation;
			positionSyncTmp = positionSync;
			rotationYSyncTmp = rotationYSync;
		}
	}

	[Command(channel = 1)]
	public void CmdUpdateTransform(Vector3 position, float rotationY)
	{
		NetworkpositionSync = position;
		NetworkrotationYSync = rotationY;
	}

	public void UpdatePosition()
	{
		if (Motor != null)
		{
			Motor.MovementIndex = MovementIndex;
			Motor.isEnabled = (IsMine || isServerControl);
		}
		OnTransformSyn();
		float num = 1f / Time.deltaTime;
		float num2 = num / currentSendingRate * Time.deltaTime;
		if (Time.time > timeTmpsending + num2)
		{
			if (IsAlive)
			{
				if (base.isLocalPlayer)
				{
					Vector3 position = base.transform.position;
					Vector3 eulerAngles = base.transform.rotation.eulerAngles;
					CallCmdUpdateTransform(position, eulerAngles.y);
				}
				else if (base.isServer && NetID == -1)
				{
					Vector3 position2 = base.transform.position;
					Vector3 eulerAngles2 = base.transform.rotation.eulerAngles;
					CallCmdUpdateTransform(position2, eulerAngles2.y);
				}
			}
			timeTmpsending = Time.time;
		}
		if ((!base.isLocalPlayer && NetID != -1) || (!base.isServer && NetID == -1))
		{
			float t = (Time.time - timeLastTrip) / latencyTime;
			if (base.transform.parent == null)
			{
				positionInterpolate = Vector3.Lerp(positionLate, positionSync, t);
				base.transform.position = Vector3.Lerp(base.transform.position, positionInterpolate, 0.6f);
			}
			Quaternion rotation = base.transform.rotation;
			Vector3 eulerAngles3 = rotation.eulerAngles;
			float x = eulerAngles3.x;
			float y = rotationYSync;
			Vector3 eulerAngles4 = rotation.eulerAngles;
			rotation.eulerAngles = new Vector3(x, y, eulerAngles4.z);
			rotationInterpolate = Quaternion.Lerp(base.transform.rotation, rotation, t);
			base.transform.rotation = rotationInterpolate;
		}
		if (Motor != null && Motor.isEnabled)
		{
			MoveVelocity = Motor.movement.velocity;
		}
		else
		{
			Vector3 b = (base.transform.position - previousPosition) / Time.deltaTime;
			previousPosition = base.transform.position;
			b.y = 0f;
			MoveVelocity = Vector3.Lerp(MoveVelocity, b, 30f * Time.deltaTime);
		}
		MoveAnimation();
	}

	public void AttackAnimation(int attacktype)
	{
		AttackType = attacktype;
		CallCmdAttackAnimation((byte)attacktype);
	}

	public void AttackAnimation()
	{
		CallCmdAttackAnimation((byte)AttackType);
	}

	[ClientRpc(channel = 0)]
	private void RpcAttackAnimation(byte attacktype)
	{
		PlayAttackAnimation(attacking: true, attacktype);
	}

	[Command(channel = 0)]
	private void CmdAttackAnimation(byte attacktype)
	{
		CallRpcAttackAnimation(attacktype);
	}

	public void AttackTo(Vector3 direction, byte attacktype)
	{
		CallCmdattackTo(direction, attacktype);
	}

	[Command(channel = 0)]
	private void CmdattackTo(Vector3 direction, byte attacktype)
	{
		PlayAttackAnimation(attacking: true, attacktype);
	}

	[Command(channel = 0)]
	public void CmddoDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		CallRpcdoDamage(origin, direction, num, spread, seed, damage, distance, penetrate, id, team);
	}

	[ClientRpc(channel = 0)]
	public void RpcdoDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		doDamage(origin, direction, num, spread, seed, damage, distance, penetrate, id, team);
	}

	[Command(channel = 0)]
	public void CmddoDamagebyItemIndex(Vector3 origin, Vector3 direction, int itemid, byte seed)
	{
		CallRpcdoDamagebyItemIndex(origin, direction, itemid, seed);
	}

	[ClientRpc(channel = 0)]
	public void RpcdoDamagebyItemIndex(Vector3 origin, Vector3 direction, int itemid, byte seed)
	{
		FPSItemEquipment fPSitem = UnitZ.itemManager.GetFPSitem(itemid);
		if (fPSitem != null)
		{
			FPSWeaponEquipment component = fPSitem.GetComponent<FPSWeaponEquipment>();
			if (component != null)
			{
				doDamage(origin, direction, component.BulletNum, component.Spread, seed, component.Damage, component.Distance, component.MaxPenetrate, NetID, Team);
			}
		}
	}

	public void doDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		if ((bool)rayActive && rayActive.ShootRay(origin, direction, num, spread, seed, damage, distance, penetrate, id, team))
		{
			PlayDamageSound();
		}
		if ((bool)inventory && !IsMine)
		{
			inventory.EquipmentOnAction(direction, num, spread, seed);
		}
	}

	public void DoDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		CallCmddoDamage(origin, direction, num, spread, seed, damage, distance, penetrate, id, team);
	}

	public void DoDamage()
	{
		CallCmddoDamage(base.transform.position + DamageOffset, base.transform.forward, 1, 0, 1, Damage, DamageLength, Penetrate, NetID, Team);
	}

	public void DoDamageByItemIndex(Vector3 origin, Vector3 direction, int itemid, byte seed)
	{
		CallCmddoDamagebyItemIndex(origin, direction, itemid, seed);
	}

	[Command(channel = 0)]
	public void CmddoOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		CallRpcdoOverlapDamage(origin, direction, damage, distance, dot, id, team);
	}

	[ClientRpc(channel = 0)]
	public void RpcdoOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		doOverlapDamage(origin, direction, damage, distance, dot, id, team);
	}

	public void doOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		if ((bool)rayActive && rayActive.Overlap(origin, direction, damage, distance, dot, id, team))
		{
			PlayDamageSound();
		}
		if ((bool)inventory && !IsMine)
		{
			inventory.EquipmentOnAction(direction, 1, 0, 0);
		}
	}

	public void DoOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		if ((bool)rayActive && rayActive.OverlapTest(origin, direction, damage, distance, dot, id, team))
		{
			PlayDamageSound();
		}
		CallCmddoOverlapDamage(origin, direction, damage, distance, dot, id, team);
	}

	public void Checking(Vector3 origin, Vector3 direction)
	{
		if ((bool)rayActive)
		{
			rayActive.CheckingRay(origin, direction);
		}
	}

	public void Interactive(GameObject target)
	{
		NetworkIdentity component = target.GetComponent<NetworkIdentity>();
		if (component != null)
		{
			CallCmdDirectObjectInteractive(component.netId);
		}
	}

	public void Interactive(Vector3 origin, Vector3 direction)
	{
		if (base.isLocalPlayer)
		{
			CallCmdInteractive(origin, direction);
			if ((bool)rayActive)
			{
				rayActive.ActiveLocalRay(origin, direction);
			}
		}
	}

	public void PickupItemCallback(ItemData item)
	{
		CallTargetReciveItem(base.connectionToClient, item.ItemID, item.NumTag, item.Quantity);
	}

	[TargetRpc]
	public void TargetReciveItem(NetworkConnection target, string itemid, int numtag, int num)
	{
		ItemData itemDataByID = UnitZ.itemManager.GetItemDataByID(itemid);
		if (!(inventory != null) || !(itemDataByID != null) || !inventory.AddItemTest(itemDataByID, num))
		{
			return;
		}
		if (inventory.stickerTarget != null)
		{
			if (!inventory.DropItemBySticker(inventory.stickerTarget))
			{
				inventory.DropItemBySameEquipType(itemDataByID);
			}
			ItemCollector itemCollector = inventory.AddItemByItemData(itemDataByID, num, numtag, inventory.stickerTarget.Index);
			if (itemCollector != null)
			{
				inventory.EquipItemToStickerByCollector(itemCollector, inventory.stickerTarget);
				inventory.OnViewChanged();
			}
			inventory.stickerTarget = null;
		}
		else
		{
			inventory.DropItemBySameEquipType(itemDataByID);
			inventory.AddItemByItemData(itemDataByID, num, numtag, -1);
		}
		if ((bool)itemDataByID.SoundPickup)
		{
			AudioSource.PlayClipAtPoint(itemDataByID.SoundPickup, base.transform.position);
		}
	}

	public void PickupItemBackpackCallback(ItemBackpack item)
	{
		CallTargetReciveItemBackpack(base.connectionToClient, item.SyncItemdata);
	}

	[TargetRpc]
	public void TargetReciveItemBackpack(NetworkConnection target, string itemdata)
	{
		if (inventory != null && itemdata != string.Empty)
		{
			inventory.AddItemFromText(itemdata);
		}
	}

	public void PickupStockCallback(ItemStocker stocker)
	{
		inventory.PeerTrade = stocker.inventory;
		stocker.inventory.PeerTrade = inventory;
		CallTargetReciveStock(base.connectionToClient, stocker.netId);
	}

	[TargetRpc]
	public void TargetReciveStock(NetworkConnection target, NetworkInstanceId objectid)
	{
		GameObject gameObject = ClientScene.FindLocalObject(objectid);
		if ((bool)gameObject)
		{
			ItemStocker component = gameObject.GetComponent<ItemStocker>();
			if ((bool)component)
			{
				component.inventory.PeerTrade = inventory;
				inventory.PeerTrade = component.inventory;
				component.PickUpStock(base.gameObject);
			}
		}
	}

	[Command(channel = 0)]
	private void CmdDirectObjectInteractive(NetworkInstanceId objectid)
	{
		GameObject gameObject = ClientScene.FindLocalObject(objectid);
		if ((bool)gameObject)
		{
			gameObject.SendMessage("Pickup", base.gameObject, SendMessageOptions.DontRequireReceiver);
		}
	}

	[Command(channel = 0)]
	private void CmdInteractive(Vector3 origin, Vector3 direction)
	{
		if ((bool)rayActive)
		{
			rayActive.ActiveRay(origin, direction);
		}
	}

	public void Move(Vector3 directionVector)
	{
		if ((bool)Motor && Motor.isActiveAndEnabled)
		{
			Motor.inputMoveDirection = directionVector;
		}
	}

	public void PlayIdleSound()
	{
		if ((bool)Audiosource && SoundIdle.Length > 0)
		{
			Audiosource.PlayOneShot(SoundIdle[Random.Range(0, SoundIdle.Length)]);
		}
	}

	public void PlayDamageSound()
	{
		if ((bool)Audiosource && DamageSound.Length > 0)
		{
			Audiosource.PlayOneShot(DamageSound[Random.Range(0, DamageSound.Length)]);
		}
	}

	public void RemoveCharacterData()
	{
		if (base.isServer && (bool)UnitZ.playerSave)
		{
			UnitZ.playerSave.DeleteSave(UserID, CharacterKey, UserName);
		}
	}

	public void SaveCharacterData(bool saveToHost)
	{
		string playerSaveToText = UnitZ.playerSave.GetPlayerSaveToText(this);
		if (saveToHost)
		{
			CallCmdSaveCharacterData(playerSaveToText);
		}
		else if ((bool)UnitZ.playerSave)
		{
			UnitZ.playerSave.SaveToLocal(playerSaveToText);
		}
	}

	[Command(channel = 0)]
	private void CmdSaveCharacterData(string savedata)
	{
		if ((bool)UnitZ.playerSave)
		{
			UnitZ.playerSave.SaveToServer(savedata);
		}
	}

	public void LoadCharacterData(bool saveToHost)
	{
		string hasKey = UserID + "_" + SceneManager.GetActiveScene().name + "_" + CharacterKey + "_" + UserName;
		if (base.isLocalPlayer)
		{
			if (saveToHost)
			{
				CallCmdGetSaveData(hasKey);
			}
			else if ((bool)UnitZ.playerSave)
			{
				string dataFromLocal = UnitZ.playerSave.GetDataFromLocal(hasKey);
				UnitZ.playerSave.ReceiveDataAndApply(dataFromLocal, this);
			}
		}
	}

	[Command(channel = 0)]
	private void CmdGetSaveData(string hasKey)
	{
		if (!(UserID == string.Empty))
		{
			string dataFromServer = UnitZ.playerSave.GetDataFromServer(hasKey);
			CallTargetGetData(base.connectionToClient, dataFromServer);
		}
	}

	[TargetRpc(channel = 0)]
	public void TargetGetData(NetworkConnection target, string data)
	{
		if ((bool)UnitZ.playerSave)
		{
			UnitZ.playerSave.ReceiveDataAndApply(data, this);
		}
	}

	[Command(channel = 0)]
	public void CmdRequestSpawnObject(Vector3 position, Quaternion rotation, string itemID, string itemData)
	{
		ItemData itemDataByID = UnitZ.itemManager.GetItemDataByID(itemID);
		if (!itemDataByID || !itemDataByID.ItemFPS)
		{
			return;
		}
		FPSItemPlacing component = itemDataByID.ItemFPS.GetComponent<FPSItemPlacing>();
		if ((bool)component && (bool)component.Item)
		{
			GameObject gameObject = UnitZ.gameNetwork.RequestSpawnObject(component.Item, position, rotation);
			if ((bool)gameObject)
			{
				ObjectPlacing component2 = gameObject.GetComponent<ObjectPlacing>();
				component2.SetItemUID(component2.GetUniqueID());
				component2.SetItemID(itemID);
				component2.SetItemData(itemData);
			}
		}
	}

	[Command(channel = 0)]
	public void CmdRequestThrowObject(Vector3 position, Quaternion rotation, string itemID, Vector3 force)
	{
		ItemData itemDataByID = UnitZ.itemManager.GetItemDataByID(itemID);
		if (!itemDataByID || !itemDataByID.ItemFPS)
		{
			return;
		}
		FPSItemThrow component = itemDataByID.ItemFPS.GetComponent<FPSItemThrow>();
		if (!component || !component.Item)
		{
			return;
		}
		GameObject gameObject = UnitZ.gameNetwork.RequestSpawnObject(component.Item, position, rotation);
		if ((bool)gameObject)
		{
			DamageBase component2 = gameObject.GetComponent<DamageBase>();
			if ((bool)component2)
			{
				component2.NetworkOwnerID = NetID;
				component2.NetworkOwnerTeam = Team;
			}
			if ((bool)gameObject.GetComponent<Rigidbody>())
			{
				gameObject.GetComponent<Rigidbody>().AddForce(force, ForceMode.Impulse);
			}
		}
	}

	[Command(channel = 0)]
	public void CmdSendMessage(string text)
	{
		CallRpcGotMessage(text);
	}

	[ClientRpc(channel = 0)]
	private void RpcGotMessage(string text)
	{
		if ((bool)UnitZ.NetworkGameplay)
		{
			UnitZ.NetworkGameplay.chatLog.AddLog(text);
		}
	}

	[Command]
	public void CmdOnSpawned(Vector3 position)
	{
		base.transform.position = position;
		NetworkpositionSync = position;
		Vector3 eulerAngles = base.transform.rotation.eulerAngles;
		NetworkrotationYSync = eulerAngles.y;
		positionSyncTmp = positionSync;
		rotationYSyncTmp = rotationYSync;
		positionLate = positionSync;
		positionLastTrip = positionSync;
		CallRpcOnSpawned(position);
	}

	[ClientRpc]
	private void RpcOnSpawned(Vector3 position)
	{
		base.transform.position = position;
		NetworkpositionSync = position;
		Vector3 eulerAngles = base.transform.rotation.eulerAngles;
		NetworkrotationYSync = eulerAngles.y;
		positionSyncTmp = positionSync;
		rotationYSyncTmp = rotationYSync;
		positionLate = positionSync;
		positionLastTrip = positionSync;
	}

	private void UNetVersion()
	{
	}

	protected static void InvokeCmdCmdChangeState(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdChangeState called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdChangeState((byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmdUpdateTransform(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdUpdateTransform called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdUpdateTransform(reader.ReadVector3(), reader.ReadSingle());
		}
	}

	protected static void InvokeCmdCmdAttackAnimation(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdAttackAnimation called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdAttackAnimation((byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmdattackTo(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdattackTo called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdattackTo(reader.ReadVector3(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmddoDamage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmddoDamage called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmddoDamage(reader.ReadVector3(), reader.ReadVector3(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), reader.ReadSingle(), (byte)reader.ReadPackedUInt32(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmddoDamagebyItemIndex(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmddoDamagebyItemIndex called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmddoDamagebyItemIndex(reader.ReadVector3(), reader.ReadVector3(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmddoOverlapDamage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmddoOverlapDamage called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmddoOverlapDamage(reader.ReadVector3(), reader.ReadVector3(), (byte)reader.ReadPackedUInt32(), reader.ReadSingle(), reader.ReadSingle(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeCmdCmdDirectObjectInteractive(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdDirectObjectInteractive called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdDirectObjectInteractive(reader.ReadNetworkId());
		}
	}

	protected static void InvokeCmdCmdInteractive(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdInteractive called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdInteractive(reader.ReadVector3(), reader.ReadVector3());
		}
	}

	protected static void InvokeCmdCmdSaveCharacterData(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdSaveCharacterData called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdSaveCharacterData(reader.ReadString());
		}
	}

	protected static void InvokeCmdCmdGetSaveData(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdGetSaveData called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdGetSaveData(reader.ReadString());
		}
	}

	protected static void InvokeCmdCmdRequestSpawnObject(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdRequestSpawnObject called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdRequestSpawnObject(reader.ReadVector3(), reader.ReadQuaternion(), reader.ReadString(), reader.ReadString());
		}
	}

	protected static void InvokeCmdCmdRequestThrowObject(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdRequestThrowObject called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdRequestThrowObject(reader.ReadVector3(), reader.ReadQuaternion(), reader.ReadString(), reader.ReadVector3());
		}
	}

	protected static void InvokeCmdCmdSendMessage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdSendMessage called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdSendMessage(reader.ReadString());
		}
	}

	protected static void InvokeCmdCmdOnSpawned(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("Command CmdOnSpawned called on client.");
		}
		else
		{
			((CharacterSystem)obj).CmdOnSpawned(reader.ReadVector3());
		}
	}

	public void CallCmdChangeState(byte state)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdChangeState called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdChangeState(state);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdChangeState);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.WritePackedUInt32(state);
		SendCommandInternal(networkWriter, 0, "CmdChangeState");
	}

	public void CallCmdUpdateTransform(Vector3 position, float rotationY)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdUpdateTransform called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdUpdateTransform(position, rotationY);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdUpdateTransform);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(position);
		networkWriter.Write(rotationY);
		SendCommandInternal(networkWriter, 1, "CmdUpdateTransform");
	}

	public void CallCmdAttackAnimation(byte attacktype)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdAttackAnimation called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdAttackAnimation(attacktype);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdAttackAnimation);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.WritePackedUInt32(attacktype);
		SendCommandInternal(networkWriter, 0, "CmdAttackAnimation");
	}

	public void CallCmdattackTo(Vector3 direction, byte attacktype)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdattackTo called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdattackTo(direction, attacktype);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdattackTo);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32(attacktype);
		SendCommandInternal(networkWriter, 0, "CmdattackTo");
	}

	public void CallCmddoDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmddoDamage called on server.");
			return;
		}
		if (base.isServer)
		{
			CmddoDamage(origin, direction, num, spread, seed, damage, distance, penetrate, id, team);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmddoDamage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32(num);
		networkWriter.WritePackedUInt32(spread);
		networkWriter.WritePackedUInt32(seed);
		networkWriter.WritePackedUInt32(damage);
		networkWriter.Write(distance);
		networkWriter.WritePackedUInt32(penetrate);
		networkWriter.WritePackedUInt32((uint)id);
		networkWriter.WritePackedUInt32(team);
		SendCommandInternal(networkWriter, 0, "CmddoDamage");
	}

	public void CallCmddoDamagebyItemIndex(Vector3 origin, Vector3 direction, int itemid, byte seed)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmddoDamagebyItemIndex called on server.");
			return;
		}
		if (base.isServer)
		{
			CmddoDamagebyItemIndex(origin, direction, itemid, seed);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmddoDamagebyItemIndex);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32((uint)itemid);
		networkWriter.WritePackedUInt32(seed);
		SendCommandInternal(networkWriter, 0, "CmddoDamagebyItemIndex");
	}

	public void CallCmddoOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmddoOverlapDamage called on server.");
			return;
		}
		if (base.isServer)
		{
			CmddoOverlapDamage(origin, direction, damage, distance, dot, id, team);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmddoOverlapDamage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32(damage);
		networkWriter.Write(distance);
		networkWriter.Write(dot);
		networkWriter.WritePackedUInt32((uint)id);
		networkWriter.WritePackedUInt32(team);
		SendCommandInternal(networkWriter, 0, "CmddoOverlapDamage");
	}

	public void CallCmdDirectObjectInteractive(NetworkInstanceId objectid)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdDirectObjectInteractive called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdDirectObjectInteractive(objectid);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdDirectObjectInteractive);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(objectid);
		SendCommandInternal(networkWriter, 0, "CmdDirectObjectInteractive");
	}

	public void CallCmdInteractive(Vector3 origin, Vector3 direction)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdInteractive called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdInteractive(origin, direction);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdInteractive);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		SendCommandInternal(networkWriter, 0, "CmdInteractive");
	}

	public void CallCmdSaveCharacterData(string savedata)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdSaveCharacterData called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdSaveCharacterData(savedata);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdSaveCharacterData);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(savedata);
		SendCommandInternal(networkWriter, 0, "CmdSaveCharacterData");
	}

	public void CallCmdGetSaveData(string hasKey)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdGetSaveData called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdGetSaveData(hasKey);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdGetSaveData);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(hasKey);
		SendCommandInternal(networkWriter, 0, "CmdGetSaveData");
	}

	public void CallCmdRequestSpawnObject(Vector3 position, Quaternion rotation, string itemID, string itemData)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdRequestSpawnObject called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdRequestSpawnObject(position, rotation, itemID, itemData);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdRequestSpawnObject);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(position);
		networkWriter.Write(rotation);
		networkWriter.Write(itemID);
		networkWriter.Write(itemData);
		SendCommandInternal(networkWriter, 0, "CmdRequestSpawnObject");
	}

	public void CallCmdRequestThrowObject(Vector3 position, Quaternion rotation, string itemID, Vector3 force)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdRequestThrowObject called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdRequestThrowObject(position, rotation, itemID, force);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdRequestThrowObject);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(position);
		networkWriter.Write(rotation);
		networkWriter.Write(itemID);
		networkWriter.Write(force);
		SendCommandInternal(networkWriter, 0, "CmdRequestThrowObject");
	}

	public void CallCmdSendMessage(string text)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdSendMessage called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdSendMessage(text);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdSendMessage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(text);
		SendCommandInternal(networkWriter, 0, "CmdSendMessage");
	}

	public void CallCmdOnSpawned(Vector3 position)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("Command function CmdOnSpawned called on server.");
			return;
		}
		if (base.isServer)
		{
			CmdOnSpawned(position);
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)5);
		networkWriter.WritePackedUInt32((uint)kCmdCmdOnSpawned);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(position);
		SendCommandInternal(networkWriter, 0, "CmdOnSpawned");
	}

	protected static void InvokeRpcRpcChangeState(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcChangeState called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcChangeState((byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcRpcAttackAnimation(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcAttackAnimation called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcAttackAnimation((byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcRpcdoDamage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcdoDamage called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcdoDamage(reader.ReadVector3(), reader.ReadVector3(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32(), reader.ReadSingle(), (byte)reader.ReadPackedUInt32(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcRpcdoDamagebyItemIndex(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcdoDamagebyItemIndex called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcdoDamagebyItemIndex(reader.ReadVector3(), reader.ReadVector3(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcRpcdoOverlapDamage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcdoOverlapDamage called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcdoOverlapDamage(reader.ReadVector3(), reader.ReadVector3(), (byte)reader.ReadPackedUInt32(), reader.ReadSingle(), reader.ReadSingle(), (int)reader.ReadPackedUInt32(), (byte)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcRpcGotMessage(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcGotMessage called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcGotMessage(reader.ReadString());
		}
	}

	protected static void InvokeRpcRpcOnSpawned(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("RPC RpcOnSpawned called on server.");
		}
		else
		{
			((CharacterSystem)obj).RpcOnSpawned(reader.ReadVector3());
		}
	}

	protected static void InvokeRpcTargetReciveItem(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("TargetRPC TargetReciveItem called on server.");
		}
		else
		{
			((CharacterSystem)obj).TargetReciveItem(ClientScene.readyConnection, reader.ReadString(), (int)reader.ReadPackedUInt32(), (int)reader.ReadPackedUInt32());
		}
	}

	protected static void InvokeRpcTargetReciveItemBackpack(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("TargetRPC TargetReciveItemBackpack called on server.");
		}
		else
		{
			((CharacterSystem)obj).TargetReciveItemBackpack(ClientScene.readyConnection, reader.ReadString());
		}
	}

	protected static void InvokeRpcTargetReciveStock(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("TargetRPC TargetReciveStock called on server.");
		}
		else
		{
			((CharacterSystem)obj).TargetReciveStock(ClientScene.readyConnection, reader.ReadNetworkId());
		}
	}

	protected static void InvokeRpcTargetGetData(NetworkBehaviour obj, NetworkReader reader)
	{
		if (!NetworkClient.active)
		{
			UnityEngine.Debug.LogError("TargetRPC TargetGetData called on server.");
		}
		else
		{
			((CharacterSystem)obj).TargetGetData(ClientScene.readyConnection, reader.ReadString());
		}
	}

	public void CallRpcChangeState(byte state)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcChangeState called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcChangeState);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.WritePackedUInt32(state);
		SendRPCInternal(networkWriter, 0, "RpcChangeState");
	}

	public void CallRpcAttackAnimation(byte attacktype)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcAttackAnimation called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcAttackAnimation);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.WritePackedUInt32(attacktype);
		SendRPCInternal(networkWriter, 0, "RpcAttackAnimation");
	}

	public void CallRpcdoDamage(Vector3 origin, Vector3 direction, byte num, byte spread, byte seed, byte damage, float distance, byte penetrate, int id, byte team)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcdoDamage called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcdoDamage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32(num);
		networkWriter.WritePackedUInt32(spread);
		networkWriter.WritePackedUInt32(seed);
		networkWriter.WritePackedUInt32(damage);
		networkWriter.Write(distance);
		networkWriter.WritePackedUInt32(penetrate);
		networkWriter.WritePackedUInt32((uint)id);
		networkWriter.WritePackedUInt32(team);
		SendRPCInternal(networkWriter, 0, "RpcdoDamage");
	}

	public void CallRpcdoDamagebyItemIndex(Vector3 origin, Vector3 direction, int itemid, byte seed)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcdoDamagebyItemIndex called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcdoDamagebyItemIndex);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32((uint)itemid);
		networkWriter.WritePackedUInt32(seed);
		SendRPCInternal(networkWriter, 0, "RpcdoDamagebyItemIndex");
	}

	public void CallRpcdoOverlapDamage(Vector3 origin, Vector3 direction, byte damage, float distance, float dot, int id, byte team)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcdoOverlapDamage called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcdoOverlapDamage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(origin);
		networkWriter.Write(direction);
		networkWriter.WritePackedUInt32(damage);
		networkWriter.Write(distance);
		networkWriter.Write(dot);
		networkWriter.WritePackedUInt32((uint)id);
		networkWriter.WritePackedUInt32(team);
		SendRPCInternal(networkWriter, 0, "RpcdoOverlapDamage");
	}

	public void CallRpcGotMessage(string text)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcGotMessage called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcGotMessage);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(text);
		SendRPCInternal(networkWriter, 0, "RpcGotMessage");
	}

	public void CallRpcOnSpawned(Vector3 position)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("RPC Function RpcOnSpawned called on client.");
			return;
		}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kRpcRpcOnSpawned);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(position);
		SendRPCInternal(networkWriter, 0, "RpcOnSpawned");
	}

	public void CallTargetReciveItem(NetworkConnection target, string itemid, int numtag, int num)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("TargetRPC Function TargetReciveItem called on client.");
			return;
		}
		//if (target.connectionId == 0)
		//{
		//	UnityEngine.Debug.LogError("TargetRPC Function TargetReciveItem called on connection to server");
		//	return;
		//}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kTargetRpcTargetReciveItem);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(itemid);
		networkWriter.WritePackedUInt32((uint)numtag);
		networkWriter.WritePackedUInt32((uint)num);
		SendTargetRPCInternal(target, networkWriter, 0, "TargetReciveItem");
	}

	public void CallTargetReciveItemBackpack(NetworkConnection target, string itemdata)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("TargetRPC Function TargetReciveItemBackpack called on client.");
			return;
		}
		//if (target.connectionId == 0)
		//{
		//	UnityEngine.Debug.LogError("TargetRPC Function TargetReciveItemBackpack called on connection to server");
		//	return;
		//}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kTargetRpcTargetReciveItemBackpack);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(itemdata);
		SendTargetRPCInternal(target, networkWriter, 0, "TargetReciveItemBackpack");
	}

	public void CallTargetReciveStock(NetworkConnection target, NetworkInstanceId objectid)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("TargetRPC Function TargetReciveStock called on client.");
			return;
		}
		//target is UnityEngine.Networking.ULocalConnectionToServer
		//if (target.connectionId == 0)
		//{
		//	UnityEngine.Debug.LogError("TargetRPC Function TargetReciveStock called on connection to server");
		//	return;
		//}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kTargetRpcTargetReciveStock);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(objectid);
		SendTargetRPCInternal(target, networkWriter, 0, "TargetReciveStock");
	}

	public void CallTargetGetData(NetworkConnection target, string data)
	{
		if (!NetworkServer.active)
		{
			UnityEngine.Debug.LogError("TargetRPC Function TargetGetData called on client.");
			return;
		}
		//if (target.connectionId == 0)
		//{
		//	UnityEngine.Debug.LogError("TargetRPC Function TargetGetData called on connection to server");
		//	return;
		//}
		NetworkWriter networkWriter = new NetworkWriter();
		networkWriter.Write((short)0);
		networkWriter.Write((short)2);
		networkWriter.WritePackedUInt32((uint)kTargetRpcTargetGetData);
		networkWriter.Write(GetComponent<NetworkIdentity>().netId);
		networkWriter.Write(data);
		SendTargetRPCInternal(target, networkWriter, 0, "TargetGetData");
	}

	static CharacterSystem()
	{
		kCmdCmdChangeState = 878930889;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdChangeState, InvokeCmdCmdChangeState);
		kCmdCmdUpdateTransform = 1283276203;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdUpdateTransform, InvokeCmdCmdUpdateTransform);
		kCmdCmdAttackAnimation = -1854539996;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdAttackAnimation, InvokeCmdCmdAttackAnimation);
		kCmdCmdattackTo = -544955717;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdattackTo, InvokeCmdCmdattackTo);
		kCmdCmddoDamage = -1127953486;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmddoDamage, InvokeCmdCmddoDamage);
		kCmdCmddoDamagebyItemIndex = 88082422;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmddoDamagebyItemIndex, InvokeCmdCmddoDamagebyItemIndex);
		kCmdCmddoOverlapDamage = 1055893747;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmddoOverlapDamage, InvokeCmdCmddoOverlapDamage);
		kCmdCmdDirectObjectInteractive = -819393982;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdDirectObjectInteractive, InvokeCmdCmdDirectObjectInteractive);
		kCmdCmdInteractive = 93629418;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdInteractive, InvokeCmdCmdInteractive);
		kCmdCmdSaveCharacterData = -564077826;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdSaveCharacterData, InvokeCmdCmdSaveCharacterData);
		kCmdCmdGetSaveData = -1745667771;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdGetSaveData, InvokeCmdCmdGetSaveData);
		kCmdCmdRequestSpawnObject = 1823636099;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdRequestSpawnObject, InvokeCmdCmdRequestSpawnObject);
		kCmdCmdRequestThrowObject = -723144274;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdRequestThrowObject, InvokeCmdCmdRequestThrowObject);
		kCmdCmdSendMessage = -1059021721;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdSendMessage, InvokeCmdCmdSendMessage);
		kCmdCmdOnSpawned = 2093845891;
		NetworkBehaviour.RegisterCommandDelegate(typeof(CharacterSystem), kCmdCmdOnSpawned, InvokeCmdCmdOnSpawned);
		kRpcRpcChangeState = -919493069;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcChangeState, InvokeRpcRpcChangeState);
		kRpcRpcAttackAnimation = 1181543566;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcAttackAnimation, InvokeRpcRpcAttackAnimation);
		kRpcRpcdoDamage = -1179338360;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcdoDamage, InvokeRpcRpcdoDamage);
		kRpcRpcdoDamagebyItemIndex = -779470752;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcdoDamagebyItemIndex, InvokeRpcRpcdoDamagebyItemIndex);
		kRpcRpcdoOverlapDamage = -202989987;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcdoOverlapDamage, InvokeRpcRpcdoOverlapDamage);
		kRpcRpcGotMessage = -1095580631;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcGotMessage, InvokeRpcRpcGotMessage);
		kRpcRpcOnSpawned = 500914797;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kRpcRpcOnSpawned, InvokeRpcRpcOnSpawned);
		kTargetRpcTargetReciveItem = -1003448204;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kTargetRpcTargetReciveItem, InvokeRpcTargetReciveItem);
		kTargetRpcTargetReciveItemBackpack = -412294124;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kTargetRpcTargetReciveItemBackpack, InvokeRpcTargetReciveItemBackpack);
		kTargetRpcTargetReciveStock = -1032878635;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kTargetRpcTargetReciveStock, InvokeRpcTargetReciveStock);
		kTargetRpcTargetGetData = -2068206649;
		NetworkBehaviour.RegisterRpcDelegate(typeof(CharacterSystem), kTargetRpcTargetGetData, InvokeRpcTargetGetData);
		NetworkCRC.RegisterBehaviour("CharacterSystem", 0);
	}

	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool flag = base.OnSerialize(writer, forceAll);
		if (forceAll)
		{
			writer.Write(CharacterKey);
			writer.WritePackedUInt32(MovementIndex);
			writer.Write(positionSync);
			writer.Write(rotationYSync);
			return true;
		}
		bool flag2 = false;
		if ((base.syncVarDirtyBits & 0x40) != 0)
		{
			if (!flag2)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag2 = true;
			}
			writer.Write(CharacterKey);
		}
		if ((base.syncVarDirtyBits & 0x80) != 0)
		{
			if (!flag2)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag2 = true;
			}
			writer.WritePackedUInt32(MovementIndex);
		}
		if ((base.syncVarDirtyBits & 0x100) != 0)
		{
			if (!flag2)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag2 = true;
			}
			writer.Write(positionSync);
		}
		if ((base.syncVarDirtyBits & 0x200) != 0)
		{
			if (!flag2)
			{
				writer.WritePackedUInt32(base.syncVarDirtyBits);
				flag2 = true;
			}
			writer.Write(rotationYSync);
		}
		if (!flag2)
		{
			writer.WritePackedUInt32(base.syncVarDirtyBits);
		}
		return flag2 | flag;
	}

	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		base.OnDeserialize(reader, initialState);
		if (initialState)
		{
			CharacterKey = reader.ReadString();
			MovementIndex = (byte)reader.ReadPackedUInt32();
			positionSync = reader.ReadVector3();
			rotationYSync = reader.ReadSingle();
			return;
		}
		int num = (int)reader.ReadPackedUInt32();
		if ((num & 0x40) != 0)
		{
			CharacterKey = reader.ReadString();
		}
		if ((num & 0x80) != 0)
		{
			MovementIndex = (byte)reader.ReadPackedUInt32();
		}
		if ((num & 0x100) != 0)
		{
			positionSync = reader.ReadVector3();
		}
		if ((num & 0x200) != 0)
		{
			rotationYSync = reader.ReadSingle();
		}
	}
}
